package ua.kpi.JavaTraning5.domain;

import javax.swing.*;
import java.awt.*;
import java.util.*;
import java.util.List;

/**
 * This class extends form JPanel and it creates field for move in lake.
 *
 * @author Vitaliy Vasylenko <apa4i007@gmail.com>
 * @version 1.0
 * @since 2013-05-29
 */

public class Grid extends JPanel {

    private List<Point> fillCells;

    public Grid() {
        fillCells = new ArrayList<Point>(25);
    }

    /**
     * The method moves the predators at a given distance.
     *
     * @param grid - The grid where need to paint cells
     */
    @Override
    protected void paintComponent(Graphics grid) {
        super.paintComponent(grid);
        for (Point fillCell : fillCells) {
            int cellX = 1 + (fillCell.x * 10);
            int cellY = 1 + (fillCell.y * 10);
            grid.setColor(Color.RED);
            grid.fillRect(cellX, cellY, 10, 10);
        }
        grid.setColor(Color.BLACK);
        grid.drawRect(10, 10, 90, 90);

        for (int i = 10; i <= 110; i += 10) {
            grid.drawLine(i, 10, i, 110);
        }

        for (int i = 10; i <= 110; i += 10) {
            grid.drawLine(10, i, 110, i);
        }
    }

    /**
     * The method fills the cell in the field.
     *
     * @param x - axis coordinate x
     * @param y - axis coordinate y
     */
    public void fillCell(int x, int y) {
        fillCells.add(new Point(x, y));
        repaint();
    }

}